<?php
require 'vendor/autoload.php';

echo "Validating XML and DB Sources \n";
validateAllSourcesExistOnDB();
echo "Saving News into DB \n";
saveAllNewsFromONlineRss();
echo "Creating Trending News And WordsFile \n";
createTrendingNewsAndWordsFile();
echo "Creating Twitter Feeds \n";
createTwitterFeeds();

function saveAllNewsFromONlineRss(){

 			$newsPersistor =  ApplicationContext::getServices('newsPersistor');
 			$rssManager =  ApplicationContext::getServices('rssManager');
 			$newsArray = $rssManager->getAllNewsFromRemote();
			//var_dump($newsArray);
 			foreach ($newsArray as $news){
 				$result = $newsPersistor->saveNews($news);
 				//var_dump($result);
 			}
}
 	
function validateAllSourcesExistOnDB(){

		$rssSM = ApplicationContext::getServices('rssSourceManager');
		$rssSM->validateAllSourcesExistOnDB();
}

function createTrendingNewsAndWordsFile(){

	$htmlCreator = ApplicationContext::getServices('htmlCreator');
	$htmlCreator->createTrendingWordsFile();
	$htmlCreator->createTrendingNewsFile();
}

function createTwitterFeeds(){

	$twitterPostsManager = ApplicationContext::getServices('twitterPostsManager');
	$rssfeed = $twitterPostsManager->generateRSSFeed();
	$twitterPostsManager->saveRSSFeedToFile($rssfeed);
}

?>